
from dexen.user.libs import constants as dc
from dexen.user.libs import server_api

from libs import constants


def _setCommonData(config_api):
    config_api.setDataStructure(
        attributes = {
            constants.GENOTYPE : dc.BLOB,
            constants.PHENOTYPE : dc.BLOB,
            constants.WIDTH : dc.FLOAT,
            constants.HEIGHT : dc.FLOAT,
            constants.AREA : dc.FLOAT
        }
    )


def _setCommonScripts(config_api):
    config_api.setTask(
        script_name = "initialization",             
        file_name = "tasks.initialization", 
        function_name = "initialise",
    )
    
    config_api.setTask(
        script_name = "development", 
        file_name = "tasks.development", 
        function_name = "develop", 
        select = (constants.GENOTYPE, ), 
        where = (
            (constants.GENOTYPE, dc.NOT_EQUAL, None),
            (constants.PHENOTYPE, dc.EQUAL, None)
        ), 
        count = 200
    )
    
    config_api.setTask(
        script_name = "evaluation", 
        file_name = "tasks.evaluation", 
        function_name = "evaluate",
        select = (constants.PHENOTYPE, constants.GENOTYPE), 
        where = (
            (constants.PHENOTYPE, dc.NOT_EQUAL, None),
            (constants.HEIGHT, dc.EQUAL, None),
            (constants.WIDTH, dc.EQUAL, None)            
        ), 
        count = 200        
    )
    
    config_api.setTask(
        script_name = "feedback",    
        file_name = "tasks.feedback", 
        function_name = "feedback",
        select = (constants.GENOTYPE, constants.WIDTH, constants.HEIGHT, 
                  constants.AREA),
        where = (
            (constants.AREA, dc.NOT_EQUAL, None),
        ), 
        count = 400
    )

    """
    config_api.setTask(
        script_name = "visualization",
        file_name = "tasks.visualization",
        function_name = "draw_pareto"
    )
    """
    
    config_api.setTask(
        script_name = "flex_visualization",
        file_name = "tasks.flex_visualization",
        function_name = "visualize_flex"
    )

def startup_synch():
    config_api = server_api.ConfigAPIFactory()
    config_api.setMaxIndividuals(constants.MAX_INDIVIDUALS)
    config_api.setGlobalData({constants.INITIALIZATION : 400,
                               constants.DEVELOPMENT : 200,
                               constants.EVALUATION : 200,
                               constants.FEEDBACK : 400})
    _setCommonData(config_api)
    _setCommonScripts(config_api)


def startup_asynch():
    config_api = server_api.ConfigAPIFactory()
    config_api.setMaxIndividuals(constants.MAX_INDIVIDUALS)
    config_api.setGlobalData({constants.INITIALIZATION : 200,
                               constants.DEVELOPMENT : 50,
                               constants.EVALUATION : 25,
                               constants.FEEDBACK : 50})    
    _setCommonData(config_api)
    _setCommonScripts(config_api)
    
